home *** CD-ROM | disk | FTP | other *** search
/ Dream 55 / Amiga_Dream_55.iso / RISCOS / APPS / TEXT / PS / KIT-PS.ZIP / Kit PS / !PSUtils / pl / psmerge < prev   
Text File  |  1997-01-24  |  2KB  |  93 lines

  1. @rem = '-*- Perl -*-
  2. @echo off
  3. perl -S %0.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9
  4. goto endofperl
  5. ';
  6.  
  7. # psmerge: merge PostScript files produced by same application and setup
  8. # usage: psmerge [-oout.ps] [-thorough] file1.ps file2.ps ...
  9. #
  10. # Copyright (C) Angus J. C. Duggan 1991-1995
  11. # See file LICENSE for details.
  12.  
  13. $prog = ($0 =~ s=.*/==);
  14.  
  15. while ($ARGV[0] =~ /^-/) {
  16.    $_ = shift;
  17.    if (/^-o(.+)/) {
  18.       if (!close(STDOUT) || !open(STDOUT, ">$1")) {
  19.      print STDERR "$prog: can't open $1 for output\n";
  20.      exit 1;
  21.       }
  22.    } elsif (/^-t(horough)?$/) {
  23.       $thorough = 1;
  24.    } else {
  25.       print STDERR "Usage: $prog [-oout] [-thorough] file...\n";
  26.       exit 1;
  27.    }
  28. }
  29.  
  30. $page = 0;
  31. $first = 1;
  32. $nesting = 0;
  33.  
  34. @header = ();
  35. $header = 1;
  36.  
  37. @trailer = ();
  38. $trailer = 0;
  39.  
  40. @pages = ();
  41. @body = ();
  42.  
  43. @resources = ();
  44. $inresource = 0;
  45.  
  46. while (<>) {
  47.    if (/^%%BeginFont:/ || /^%%BeginResource:/ || /^%%BeginProcSet:/) {
  48.       $inresource = 1;
  49.       push(@resources, $_);
  50.    } elsif ($inresource) {
  51.       push(@resources, $_);
  52.       $inresource = 0 if /^%%EndFont/ || /^%%EndResource/ || /^%%EndProcSet/;
  53.    } elsif (/^%%Page:/ && $nesting == 0) {
  54.       $header = $trailer = 0;
  55.       push(@pages, join("", @body)) if @body;
  56.       $page++;
  57.       @body = ("%%Page: ($page) $page\n");
  58.    } elsif (/^%%Trailer/ && $nesting == 0) {
  59.       push(@trailer, $_);
  60.       push(@pages, join("", @body)) if @body;
  61.       @body = ();
  62.       $trailer = 1;
  63.       $header = 0;
  64.    } elsif ($header) {
  65.       push(@trailer, $_);
  66.       push(@pages, join("", @body)) if @body;
  67.       @body = ();
  68.       $trailer = 1;
  69.       $header = 0;
  70.    } elsif ($trailer) {
  71.       if (/^%!/ || /%%EOF/) {
  72.      $trailer = $first = 0;
  73.       } elsif ($first) {
  74.      push(@trailer, $_);
  75.       }
  76.    } elsif (/^%%BeginDocument/ || /^%%BeginBinary/ || /^%%BeginFile/) {
  77.       push(@body, $_);
  78.       $nesting++;
  79.    } elsif (/^%%EndDocument/ || /^%%EndBinary/ || /^%%EndFile/) {
  80.       push(@body, $_);
  81.       $nesting--;
  82.    } else {
  83.       print $_ if $print;
  84.    }
  85. }
  86.  
  87. print @trailer;
  88.  
  89. exit 0;
  90. __END__
  91. :endofperl
  92.  
  93.